<template>
  <el-container>
    <el-aside width="200">
      <h1 class="logo"></h1>
      <el-menu
        :default-active="$route.path"
        class="el-menu-vertical-demo"
        @open="handleOpen"
        @close="handleClose"
        :collapse="isCollapse"
      >
        <qf-sub-menu :sideMenu="$store.state.sideMenu"></qf-sub-menu>
      </el-menu>
    </el-aside>
    <el-container>
      <!-- header部分 -->
      <el-header>
        <el-row type="flex" class="row-bg" justify="space-around">
          <el-col :span="6"
            ><div class="icon">
              <i
                :class="isCollapse ? 'el-icon-s-unfold' : 'el-icon-s-fold'"
                @click="isCollapse = !isCollapse"
              ></i></div
          ></el-col>
          <!-- el-icon-s-fold -->
          <el-col :span="6"
            ><div class="grid-content bg-purple-light">亿锋管理</div></el-col
          >
          <el-col :span="6">
            <b class="grid-content bg-purple">请登录</b>
            <b class="quit">
              <a href="#" @click="quit">退出</a>
            </b>
          </el-col>
        </el-row>
      </el-header>
      <el-main>
        <!-- main -->
        <el-breadcrumb separator="/">
          <el-breadcrumb-item :to="{ path: '/welcome' }"
            >首页</el-breadcrumb-item
          >
          <el-breadcrumb-item
            v-for="(item, index) in $store.state.breadCrum"
            :key="index"
            :to="{ name: item.name }"
            >{{ item.meta.name }}</el-breadcrumb-item
          >
        </el-breadcrumb>
        <router-view></router-view>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import { getlog } from '@/api'
import subMenu from '@/components/subMenu'
console.log(subMenu)
export default {
  components: {
    subMenu,
  },
  data() {
    return {
      isCollapse: false,

      // 搜索
      options: [],
      value: '',
      list: [],
      loading: false,
      states: [],
    }
  },
  mounted() {
    // 搜索
    this.list = this.states.map((item) => {
      return { value: `value:${item}`, label: `label:${item}` }
    })
  },
  methods: {
    // 退出登录
    /*
                1、跳转到登录页面
                2、清空token
                3、刷新页面，目的：因为addRoutes之后，数据编译无法清空，
                会导致不同角色菜单混乱
                */
    quit(e) {
      e.preventDefault() //阻止a标签默认事件
      this.$router.push('./login')
      localStorage.removeItem('yf-token')
      location.reload()
    },
    // 搜索
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true
        setTimeout(() => {
          this.loading = false
          this.options = this.list.filter((item) => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1
          })
        }, 200)
      } else {
        this.options = []
      }
    },
    handleOpen(key, keyPath) {
      // console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      // console.log(key, keyPath)
    },
  },
  beforeCreate() {
    getlog().then((res) => {
      // console.log(res)
    })
  },
}
</script>
<style>
html,
body,
head,
#app {
  height: 100%;
  margin: 0;
  padding: 0;
}
.allowSearch span {
  font-size: 16px;
}
.logo {
  height: 60px;
  background: linear-gradient(135deg, #4c67ff, #5635df);

  background-image: url(../img/logo.be8bbddf.png);
  background-size: 80%;
  background-repeat: no-repeat;
  background-position: 50%;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-header,
.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 30px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #e9eef3;
  color: #333;

  line-height: 80px;
}

.el-container {
  margin-bottom: 40px;
  height: 100%;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
